import 'package:fish_redux/fish_redux.dart';
import 'package:flutter/material.dart' hide Action;

import 'action.dart';
import 'state.dart';

Widget buildView(
    MessageState state, Dispatch dispatch, ViewService viewService) {
  return Container(
    child: ListTile(
      title: Column(
        crossAxisAlignment: CrossAxisAlignment.start,
        children: <Widget>[
          SizedBox(height: 8),
          Text(
            state.title,
            maxLines: 1,
          ),
          SizedBox(height: 8),
          Text(
            state.content.trim(),
          ),
          SizedBox(height: 8),
          Row(
            mainAxisSize: MainAxisSize.max,
            children: <Widget>[
              Text(state.creationTime,
                  style: TextStyle(fontSize: 12, color: Colors.grey)),
            ],
          )
        ],
      ),
      leading: Stack(
        children: <Widget>[
          Container(
            padding: const EdgeInsets.fromLTRB(10, 14, 10, 14),
            decoration: new BoxDecoration(
              border: new Border.all(color: Colors.grey),
              borderRadius: BorderRadius.circular(12.0),
            ),
            child: Text(
              state.tip,
              style: TextStyle(color: Colors.grey),
            ),
          ),
          Positioned(
              top: 0,
              right: 0,
              child: new CircleAvatar(
                radius: state.read == true ? 0.0 : 4.5,
                backgroundColor: Colors.red,
              )),
        ],
      ),
      onTap: () {
        if (!state.read) {
          dispatch(MessageActionCreator.onRead(state.id));
        }
      },
    ),
  );
}
